package com.lsa.edmonds.chap1;

import com.lsa.shenn.common.Task;
import com.lsa.helpers.Utils;

/**
 * @author lsa
 *
 */
public class TwoFingerMax implements Task
{
	public void doIt()
	{
	}
	
	/**
	 * $PRE: array is an arbitrary array of numbers,
	 * may include repetitions;
	 * @param array
	 * @return index of maximum element. if there are few such elements (due to repetiotions)
	 * returns either of them 
	 */
	public int findFirstIndexOfMax(int[] array)
	{
		if (array.length < 1)
			return -1;
		
		int i = 0;
		int j = 0;
		
		// $LOOP_INVARIANT: array[i] is maximum of array[0..j]
		while( j < array.length - 1)
		{
			j++;
			if (array[i] < array[j])
			{
				i = j;
			}
		}
		
		return i;
	}
}
